import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from models.invoice import Invoice

class HomeService():
	class Index(webapp.RequestHandler):
		def get(self):
			total       = 0
			outstanding = 0
			#'amount'    : (n.rate * n.hours),
			#'amountGST' : (n.rate * n.hours) + ((n.rate * n.hours) * n.taxRate)
			for n in Invoice.all():
				if n.paid:
					total += (n.rate * n.hours)
				if not n.paid:
					outstanding += (n.rate * n.hours)
				
			
			path = os.path.join(os.path.dirname(__file__), '../views/home/index.html')
			html = template.render(path, {'total' : total, 'outstanding' : outstanding})
			self.response.out.write(html)